const mongoose = require("mongoose")
const crypto = require("crypto") //引用加密模块
const ObjectId = mongoose.Schema.Types.ObjectId;
const GoodsSchema = new mongoose.Schema({
    // 商品数据模型
    nickname: String,    //商品名
    category: String,    //商品类别，狗粮、猫粮 
    material: String,    //材质类别，玩具、
    specifications: String,    //适用什么类型犬
    exclusive: String,    //贵宾专用、比熊专用等；
    packaging: String,    //包装规格比如1kg
    taste: String,   //商品口味
    special: String,   // 特殊功用比如美毛
    origin: String,   // 产地
    manufacturedate: Date,  //生产日期；
    shelflife: String,   //保质期
    supplierId: {    //关联的供应商
        type: ObjectId,
        ref: "Supplier"
    },
    featuresthat: String,   //特色说明
    price: Number,   //价格
    img: String,   //需要图路径
    salesamount: Number,  //销售数量,统计会用到
    isHot: Boolean  //热门商品
}, {
        versionKey: false,
        timestamps: {
            createdAt: 'createTime',
            updatedAt: 'updateTime'
        } //自动管理修改时间
    })
const goods = mongoose.model("goods", GoodsSchema);
async function add() {
    const count = await goods.countDocuments();
    // console.log(count);
    if (count === 0) {
        goods.create({
            nickname: "abc",    //商品名
            category: "狗粮",    //商品类别，狗粮、猫粮 
            material: "玩具",    //材质类别，玩具、
            specifications: "贵宾",    //适用什么类型犬
            exclusive: "贵宾专用",    //贵宾专用、比熊专用等；
            packaging: "10kg",    //包装规格比如1kg
            taste: "牛肉味",   //商品口味
            special: "美毛",   // 特殊功用比如美毛
            origin: "成都",   // 产地
            manufacturedate: "2000-12-31",  //生产日期；
            shelflife: "12个月",   //保质期
            supplierId: "5c9c79c0be9d5b2ff434133f",
            featuresthat: "String",   //特色说明
            price: 5,   //价格
            img: "aa",   //需要大、小图路径
            salesamount: 10,  //销售数量,统计会用到
            isHot: true  //热门商品
        })
    }
}
add();
module.exports = goods;